

import java.util.*;
import java.io.*;

import rxtokenizer.*;
/**
 *
 * @author ruslan
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
    	ConceptTypeBuilder ctb = new ConceptTypeBuilder();
    	
    	File fil = new File("concept_types.rxt");
    	Result res = ctb.addConceptType(fil);
    	if (res != Result.NO_ERROR) System.out.println(res);
    	
    	
	
    /*
	ConceptTypeStruct cts = new ConceptTypeStruct();
	
	cts.name = "digit";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "\\d";
	cts.constraintExtractingExp = "/digit minvalue=\"0\" maxvalue=\"9\"/";
	System.out.println(ctb.addConceptType(cts));

	cts.name = "digits";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digit/+";
	cts.constraintExtractingExp = "";
	System.out.println(ctb.addConceptType(cts));
	
	
	cts.name = "digits2";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digits/";
	cts.constraintExtractingExp = "/digits2 length=\"2\"/";
	System.out.println(ctb.addConceptType(cts));
	
	cts.name = "digits4";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digits/";
	cts.constraintExtractingExp = "/digits4 length=\"4\"/";
	System.out.println(ctb.addConceptType(cts));
	
	cts.name = "day";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digits2/";
	cts.constraintExtractingExp = "/day minvalue=\"1\" maxvalue=\"31\"/";
	System.out.println(ctb.addConceptType(cts));
	
	cts.name = "month";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digits2/";
	cts.constraintExtractingExp = "/month minvalue=\"1\" maxvalue=\"12\"/";
	System.out.println(ctb.addConceptType(cts));
	
	cts.name = "month2";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digits4/";
	cts.constraintExtractingExp = "/month2 minvalue=\"1\" maxvalue=\"12\"/";
	System.out.println(ctb.addConceptType(cts));
	
	cts.name = "year2";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digits2/";
	cts.constraintExtractingExp = "/year2 maxvalue=\"10\"/";
	System.out.println(ctb.addConceptType(cts));
	
	cts.name = "year4";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/digits4/";
	cts.constraintExtractingExp = "/year4 minvalue=\"2000\" maxvalue=\"2010\"/";
	System.out.println(ctb.addConceptType(cts));
	
	cts.name = "date";
	cts.conceptTypeId = ConceptTypeConst.REG_EXP_CONCEPT_TYPE;
	cts.originalExtractingExp = "/day/\\./month/\\./year2/";
	cts.constraintExtractingExp = "";
	System.out.println(ctb.addConceptType(cts));
	/* */
	
	//System.out.println(ctb.getConceptTypes().toString());
    	
    	
	IDocument doc = new StringDocument("02");
	ConceptExtractor conceptExtractor = new ConceptExtractor(ctb.getConceptTypes(), new StringDocument(doc.getText()));
	File fill = new File("extracted_concepts.rxt");
	res = conceptExtractor.extract(fill);
	if (res != Result.NO_ERROR) System.out.println(res);
	if (conceptExtractor.getConcepts()!=null) {
	    Iterator iter = conceptExtractor.getConcepts().iterator();
	    while (iter.hasNext())
	    	System.out.println(((Concept)iter.next()).toString());
	}

    }
}
